
*** Figures and Appendix for "Who’s Out of Touch? 
*** Media Misperception of Public Opinion on U.S. Foreign Policy"

cd "/Users/uctqont/Dropbox/Out of Touch/Out of Touch Replication"

log using outoftouch, replace

use "CCGA2018Leader.dta"

save "outoftouch.dta", replace

* Expert Groups

/* Clean Up Expert Group Categories */
gen groupnew = 0
replace groupnew = 1 if Group == 1 /* academic */
replace groupnew = 4 if Group == 2 /* business -> interest group category */ 
replace groupnew = 2 if Group == 3 /* congress */
replace groupnew = 3 if Group == 4 /* executive branch */
replace groupnew = 4 if Group == 5 /* interest groups -> interest group category */
replace groupnew = 4 if Group == 6 /* labor -> interest group category */
replace groupnew = 5 if Group == 7 /* media */
replace groupnew = 4 if Group == 8 /* religion -> interest group category */
replace groupnew = 6 if Group == 9 /* think tank */
replace groupnew = . if groupnew == 0
label variable groupnew "Professional Groups"
label define groupnewlabels 1 "Academic" 2 "Congress" 3 "Executive Branch" 4 "Interest Groups" 5 "Media" 6 "Think Tank"
label values groupnew groupnewlabels

/* Generate Expert Group Indicators */
gen academic = 0
replace academic = 1 if groupnew == 1
label variable academic "Academic"

gen congress = 0
replace congress = 1 if groupnew == 2
label variable congress "Congress"

gen executive = 0
replace executive = 1 if groupnew == 3
label variable executive "Executive Branch"

gen interest = 0
replace interest = 1 if groupnew == 4
label variable interest "Interest Group"

gen media = 0
replace media = 1 if groupnew == 5
label variable media "Media"

gen thinktank = 0
replace thinktank = 1 if groupnew == 6
label variable thinktank "Think Tank"

gen elite = 1

* Expert Estimates

gen activepart = 0
replace activepart = 1 if Q3 == "Active part"
replace activepart = . if Q3 == ""
label variable activepart "Active Part"

gen activepartestimate = Q3A_1/100
label variable activepartestimate "Expert Estimate of Public"

* Distance Variable

gen outoftouch = 70 - Q3A_1
gen distance = abs(outoftouch)

* Background Covariates

encode q1010, gen(partisan)
gen dem = 0
replace dem = 1 if partisan == 1
label variable dem "Democratic"

gen postgrad = 0
replace postgrad = 1 if EDU == "Postgraduate"
replace postgrad = . if EDU == ""
label variable postgrad "Postgraduate Degree"

encode AGE, gen(agecontinuous)

gen agebinary = .
replace agebinary = 0 if agecontinuous == 1 | agecontinuous == 2 | agecontinuous == 3
replace agebinary = 1 if agecontinuous == 4 | agecontinuous == 5  
label variable agebinary "Over 60"

gen gender = 0
encode GENDER, gen(gender2)
replace gender = 1 if gender2 == 2
replace gender = . if gender2 == .
label variable gender "Male"

gen white = 0
encode RACE, gen(race2)
replace white = 1 if race2 == 6
label variable white "White"

save "outoftouch.dta", replace

* Append Public Data (CCGA 2018)

use "CCGA2018Public.dta"

gen activepart = .
replace activepart = 0 if q3 == 2
replace activepart = 1 if q3 == 1

gen elite = 0

gen publicweight = weight

keep activepart elite publicweight

save "CCGA2018PublicPREMERGE.dta", replace

use "outoftouch.dta"

append using "CCGA2018PublicPREMERGE.dta"

gen groupnewpluspublic = .
replace groupnewpluspublic = 1 if Group == 1 /* academic */
replace groupnewpluspublic = 4 if Group == 2 /* business -> interest group category */ 
replace groupnewpluspublic = 2 if Group == 3 /* congress */
replace groupnewpluspublic = 3 if Group == 4 /* executive branch */
replace groupnewpluspublic = 4 if Group == 5 /* interest groups -> interest group category */
replace groupnewpluspublic = 4 if Group == 6 /* labor -> interest group category */
replace groupnewpluspublic = 5 if Group == 7 /* media */
replace groupnewpluspublic = 4 if Group == 8 /* religion -> interest group category */
replace groupnewpluspublic = 6 if Group == 9 /* think tank */
replace groupnewpluspublic = 7 if elite == 0 /* Public */
replace groupnewpluspublic = . if groupnew == 0
label variable groupnewpluspublic "Professional Groups (Plus Public)"
label define groupnewpluspubliclabels 1 "Academic" 2 "Congress" 3 "Executive Branch" ///
 4 "Interest Groups" 5 "Media" 6 "Think Tank" 7 "Public"
label values groupnewpluspublic groupnewpluspubliclabels

replace groupnew = . if groupnewpluspublic == 7

replace publicweight = 1 if publicweight == .

save "outoftouch.dta", replace

* Figure 1

gen groupnewfig1 = .
replace groupnewfig1 = 1 if groupnewpluspublic == 3
replace groupnewfig1 = 2 if groupnewpluspublic == 4
replace groupnewfig1 = 3 if groupnewpluspublic == 1
replace groupnewfig1 = 4 if groupnewpluspublic == 6
replace groupnewfig1 = 5 if groupnewpluspublic == 5
replace groupnewfig1 = 6 if groupnewpluspublic == 2
replace groupnewfig1 = 7 if groupnewpluspublic == 7

label variable groupnewfig1 "Professional Groups"
label define groupnewfig1labels 1 "Executive Branch"  2 "Interest Groups" 3 "Academic" ///
  4 "Think Tank" 5 "Media" 6 "Congress" 7 "Public"
label values groupnewfig1 groupnewfig1labels

ciplot activepart [aweight = publicweight], by(groupnewfig1) horizontal ///
 xlabel(.6(.1)1.0) ///
 graphregion(fcolor(white)) ///
 ylabel(, grid glcolor(white)) ///
 msize(vsmall) msymbol(circle) mcolor(black) ///
 name(F1, replace)
 
* Figure 2

gen groupnewfig2 = .
replace groupnewfig2 = 1 if groupnew == 2
replace groupnewfig2 = 2 if groupnew == 1
replace groupnewfig2 = 3 if groupnew == 3
replace groupnewfig2 = 4 if groupnew == 4
replace groupnewfig2 = 5 if groupnew == 6
replace groupnewfig2 = 6 if groupnew == 5
label variable groupnewfig2 "Professional Groups"
label define groupnewfig2labels 1 "Congress"  2 "Academic" 3 "Executive Branch"  ///
  4 "Interest Group" 5 "Think Tank" 6 "Media" 
label values groupnewfig2 groupnewfig2labels

ciplot activepartestimate, by(groupnewfig2) horizontal ///
 xlabel(.4(.1).7) xline(.7) ///
 graphregion(fcolor(white)) ///
 ylabel(, grid glcolor(white)) ///
 msize(vsmall) msymbol(circle) mcolor(black) ///
 name(F2, replace)
  
* Figure 3

gen groupnewfig3 = .
replace groupnewfig3 = 1 if groupnew == 2
replace groupnewfig3 = 2 if groupnew == 1
replace groupnewfig3 = 3 if groupnew == 6
replace groupnewfig3 = 4 if groupnew == 3
replace groupnewfig3 = 5 if groupnew == 4
replace groupnewfig3 = 6 if groupnew == 5
label variable groupnewfig3 "Professional Groups"
label define groupnewfig3labels 1 "Congress"   2 "Academic"  3 "Think Tank"  ///
  4 "Executive Branch" 5 "Interest Group"  6 "Media"
label values groupnewfig3 groupnewfig3labels

ciplot distance, by(groupnewfig3) horizontal ///
 xlabel(10(5)30) ///
 graphregion(fcolor(white)) ///
 ylabel(, grid glcolor(white)) ///
 msize(vsmall) msymbol(circle) mcolor(black) ///
 name(F3, replace) 
 
* Fig. 4: Active Part

reg distance academic dem postgrad agecontinuous white gender
estimates store academic

reg distance congress dem postgrad agecontinuous white gender
estimates store congress

reg distance executive dem postgrad agecontinuous white gender
estimates store executive

reg distance interest dem postgrad agecontinuous white gender
estimates store interest

reg distance media dem postgrad agecontinuous white gender
estimates store media

reg distance thinktank dem postgrad agecontinuous white gender
estimates store thinktank

coefplot (congress, label(Congress)) (executive, label(Executive)) (academic, label(Academic)) ///
 (thinktank, label(Think Tank)) (interest, label(Interest Groups)) (media, label(Media)), ///
 drop(_cons) xline(0) ///
 keep(congress executive academic thinktank interest media) ///
 level(95) nokey ///
 graphregion(fcolor(white)) ylabel(, grid glcolor(white)) ///
 msize(vsmall) msymbol(circle) mcolor(black) ///
 name(F4, replace)

* T-tests
ttest activepartestimate, by(media) /* Footnote 3 */
ttest distance, by(media)/* Footnote 4 */

* Appendix Table 1 

tabstat dem postgrad agebinary white gender, by(groupnew)

* Appendix Table 2

reg distance media dem postgrad agebinary white gender
outreg2 using "AppendixTable2.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Media") /// 
		title("Appendix Table 2. Effect of Professional Group on Distance") replace

reg distance congress dem postgrad agebinary white gender
outreg2 using "AppendixTable2.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Congress") 

reg distance executive dem postgrad agebinary white gender
outreg2 using "AppendixTable2.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Executive") 

reg distance academic dem postgrad agebinary white gender
outreg2 using "AppendixTable2.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Academic") 

reg distance thinktank dem postgrad agebinary white gender
outreg2 using "AppendixTable2.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Think Tank") 
	
reg distance interest dem postgrad agebinary white gender
outreg2 using "AppendixTable2.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Interest Group") 
		
* Appendix Table 3
		
reg distance B5.groupnew dem postgrad agebinary white gender ///
 if groupnew == 2 | groupnew == 5
outreg2 using "AppendixTable3.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Congress") /// 
		title("Appendix Table 3. Effect of Media Group on Distance") replace

reg distance B5.groupnew dem postgrad agebinary white gender ///
 if groupnew == 3 | groupnew == 5
outreg2 using "AppendixTable3.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Executive") 

reg distance B5.groupnew dem postgrad agebinary white gender ///
 if groupnew == 1 | groupnew == 5
outreg2 using "AppendixTable3.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Academic") 

reg distance B5.groupnew dem postgrad agebinary white gender ///
 if groupnew == 6 | groupnew == 5
outreg2 using "AppendixTable3.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Think Tank") 
		
reg distance B5.groupnew dem postgrad agebinary white gender ///
 if groupnew == 4 | groupnew == 5
outreg2 using "AppendixTable3.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Interest Group") 

* Appendix Table 4
		
reg distance media dem postgrad agebinary white gender activepart
outreg2 using "AppendixTable4.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Media") /// 
		title("Appendix Table 4") replace

reg distance congress dem postgrad agebinary white gender activepart
outreg2 using "AppendixTable4.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Congress") 

reg distance executive dem postgrad agebinary white gender activepart
outreg2 using "AppendixTable4.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Executive") 

reg distance academic dem postgrad agebinary white gender activepart
outreg2 using "AppendixTable4.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Academic") 

reg distance thinktank dem postgrad agebinary white gender activepart
outreg2 using "AppendixTable4.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Think Tank") 
	
reg distance interest dem postgrad agebinary white gender activepart
outreg2 using "AppendixTable4.doc", ///
        se sdec(2) bdec(2) rdec(2) coefastr nocons label ///
        ctitle("Interest Group") 
		
log close









